import java.math.BigDecimal;
import java.util.HashSet;

import squareBorderPackage.*;
import temperaturePackage.*;
import dungeonPackage.*;

/**
 * An application that inserts a shaft and a level in a composite dungeon and checks some properties of them. 
 * 
 * @version	1.0
 * @author 	Jessa Bekker & Esther Alberts
 */
public class HoofdProgramma {

	private static Orientation rootMax, shaftMax, shaftRef, levelMax, levelRef,
			shaftTeleOr, levelOr1, levelOr2, levelOr3, levelOr4, levelOr5;
	
	private static Dungeon<Square> rootDungeon, shaft, level;
	
	private static AccessibleSquare shaftSquare1, shaftTeleSquare1,
		levelSquare1, levelSquare2, levelSquare3, levelSquare4, levelSquare5;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		setUp();
		
		System.out.println("HOOFDPROGRAMMA");
		System.out.println("");
		System.out.println("RootDungeon met maximum coordinaten: "+rootMax.toString());
		System.out.println("Level met maximum coordinaten: " + levelMax.toString() + ", in rootDungeon op referentie: " + levelRef.toString());
		System.out.println("Shaft met maximum coordinaten: " + shaftMax.toString() + ", in rootDungeon op referentie: " + shaftRef.toString());
		System.out.println("");
		System.out.println("Shaft heeft een vakje met als coordinaten " + shaftMax.toString());
		System.out.println("   (de coordinaten van dit vakje in rootDungeon zijn :" + shaftRef.add(shaftMax).toString() + ").");
		System.out.println("Het vakje met als coordinaten " + levelOr2 + " in level");
		System.out.println("   (en dus coordinaten " + levelRef.add(levelOr2).toString() + " in rootDungeon), is zijn buur.");
		System.out.println("   --->   " + rootDungeon.getNeighbors(shaftRef.add(shaftMax)).contains(levelRef.add(levelOr2)));
		System.out.println("");
		System.out.println("De grens tussen de twee vorige vakjes is een muur.");
		System.out.println("   --->   " + (shaftSquare1.getSharedBorder(levelSquare2) instanceof Wall));
		System.out.println("");
		System.out.println("");
		System.out.println("Vakjes in level:");
		System.out.println(levelOr1.toString() + " heeft een vakje: " + level.hasSquareAt(levelOr1));
		System.out.println(levelOr2.toString() + " heeft een vakje: " + level.hasSquareAt(levelOr2));
		System.out.println(levelOr3.toString() + " heeft een vakje: " + level.hasSquareAt(levelOr3));
		System.out.println(levelOr4.toString() + " heeft een vakje: " + level.hasSquareAt(levelOr4));
		System.out.println(levelOr5.toString() + " heeft een vakje: " + level.hasSquareAt(levelOr5));
		System.out.println("");
		System.out.println("space van " + levelOr1.toString() + ":");
		getSpaceOf(level, levelOr1);
		System.out.println("");
		System.out.println("shaft heeft een teleportatievakje staan op " + shaftTeleOr.toString());
		System.out.println("Een avatar kan vanaf " +shaftTeleOr.toString() + " in shaft navigeren naar " +levelOr1.toString() + " in level?");
		System.out.println("   --->   " + shaftTeleSquare1.canNavigateTo(levelSquare1));
		System.out.println("Een avatar kan vanaf " +shaftTeleOr.toString() + " in shaft navigeren naar " +levelOr2.toString() + " in level?");
		System.out.println("   --->   " + shaftTeleSquare1.canNavigateTo(levelSquare2));
		System.out.println("Een avatar kan vanaf " +shaftTeleOr.toString() + " in shaft navigeren naar " +levelOr3.toString() + " in level?");
		System.out.println("   --->   " + shaftTeleSquare1.canNavigateTo(levelSquare3));
		System.out.println("Een avatar kan vanaf " +shaftTeleOr.toString() + " in shaft navigeren naar " +levelOr4.toString() + " in level?");
		System.out.println("   --->   " + shaftTeleSquare1.canNavigateTo(levelSquare4));
		System.out.println("Een avatar kan vanaf " +shaftTeleOr.toString() + " in shaft navigeren naar " +levelOr5.toString() + " in level?");
		System.out.println("   --->   " + shaftTeleSquare1.canNavigateTo(levelSquare5));
	}
	
	public static void setUp() {
		rootMax = new Orientation(100, 100, 100);
		shaftMax = new Orientation(0, 0, 10);
		shaftRef = new Orientation(20, 20, 39);
		levelMax = new Orientation(20, 20, 0);
		levelRef = new Orientation(10, 10, 50);
		
		shaftTeleOr = new Orientation(0,0,5);
		
		levelOr1 = new Orientation(9, 10, 0);
		levelOr2 = new Orientation(10, 10, 0);
		levelOr3 = new Orientation(10, 11, 0);
		levelOr4 = new Orientation(11, 11, 0);
		levelOr5 = new Orientation(11, 10, 0);
		
		rootDungeon = new CompositeDungeon<Square>(rootMax);
		shaft = new Shaft<Square>(shaftMax);
		level = new Level<Square>(levelMax);
		
		HashSet<AccessibleSquare> teleSquares = new HashSet<AccessibleSquare>();
		
		shaftSquare1 = new NormalSquare(new Temperature(25, TemperatureUnit.CELSIUS), BigDecimal.ZERO, Direction.NORTH);
		shaftTeleSquare1 = new TeleTrans(new Temperature(25, TemperatureUnit.CELSIUS), BigDecimal.ZERO, teleSquares, Direction.NORTH, false);
		
		levelSquare1 = new NormalSquare();
		levelSquare2 = new NormalSquare();
		levelSquare3 = new NormalSquare();
		levelSquare4 = new NormalSquare();
		levelSquare5 = new NormalSquare();
		
		((Teleportation) shaftTeleSquare1).addTeleSquare((AccessibleSquare) levelSquare3);
		
		shaft.setSquareAt(shaftMax, shaftSquare1);
		shaft.setSquareAt(shaftTeleOr, shaftTeleSquare1);
		
		level.setSquareAt(levelOr1, levelSquare1);
		level.setSquareAt(levelOr2, levelSquare2);
		level.setSquareAt(levelOr3, levelSquare3);
		level.setSquareAt(levelOr4, levelSquare4);
		level.setSquareAt(levelOr5, levelSquare5);
		
		((CompositeDungeon<Square>) rootDungeon).insertSubDungeon(shaftRef, shaft);
		((CompositeDungeon<Square>) rootDungeon).insertSubDungeon(levelRef, level);
	}
	
	public static void getSpaceOf(Dungeon<Square> dungeon, Orientation orientation) {
		Square spaceSquare = dungeon.getSquareAt(orientation);
		for(Square square : spaceSquare.getSpace()){
			if(dungeon.getSquares().containsValue(square))
				for(Orientation test : dungeon.getSquares().keySet())
					if(dungeon.getSquareAt(test) == square)
						System.out.println(test);
		}
	}
}
